<%@page import="org.jeecgframework.web.util.StaticValue"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<t:base type="jquery,easyui,tools,DatePicker"></t:base>
<div class="easyui-layout" fit="true">
	<div region="center" style="padding:1px;">
		<t:datagrid name="zyGenerateInspectionPlanList" checkbox="true" fitColumns="false" title="生成巡检计划" autoLoadData="false" pageList="[20,100,1000]"
			actionUrl="zyInspectionPlanController.do?generateInspectionPlandatagrid" idField="id" fit="true" queryMode="group">
			<t:dgCol title="主键"			field="id"		hidden="true"	queryMode="single"  width="120" />
			<t:dgCol title="是否在本年度默认巡检范围内"		field="inThisYearInsScope"	hidden="true"	queryMode="single"	query="true"	width="80"	
				dictionary="<%=StaticValue.DIC_TRUE_OR_FALSE_NUM %>" defaultSelectVal="<%=StaticValue.DIC_TRUE_OR_FALSE_NUM_1 %>" />
			<t:dgCol title="设备SN"			field="sn"							queryMode="single"	query="true"	width="160" />
			<t:dgCol title="机型"			field="type.typeDesc"				width="90" />
			<t:dgCol title="BP"				field="bpNo"						queryMode="single"	query="true"	width="80" />
			<t:dgCol title="省市"			field="tsTerritory.territoryName"	queryMode="single"	query="true"	width="70"	sortable="false" />
			<t:dgCol title="所在影院名称"		field="zyCinema.name"  				queryMode="single"	query="true"	width="280"	sortable="false" />
			<t:dgCol title="发货日期"		field="sendDate"    				width="85"		formatter="yyyy-MM-dd" />
			<t:dgCol title="安装日期"		field="installDate"					queryMode="group"	query="true"	width="85"		formatter="yyyy-MM-dd" />
			<t:dgCol title="保修开始日期"		field="warrantyBeginDate"			width="100"	sortable="false" formatter="yyyy-MM-dd"/>
			<t:dgCol title="保修截止日期"		field="repairEndDate"				queryMode="group"	query="true"	width="90"		formatter="yyyy-MM-dd" />
			<t:dgCol title="续保方"			field="companyOfRenewal"			width="120"	sortable="false" />
			<t:dgCol title="去年巡检日期"		field="lastYearInspectionDate"		queryMode="group"	query="true"	width="100"		formatter="yyyy-MM-dd" />
			<t:dgCol title="设备服务状态"		field="serverState"					queryMode="single"	query="true"	width="100"		dictionary="<%=StaticValue.DIC_SERVER_STATE %>" />
			<t:dgCol title="巡检服务商"		field="sendSign.shortname"				width="180"	sortable="false" dictionary="t_s_depart,id,departname"/>
			<t:dgCol title="剩余巡检次数"		field="residualIpCount"				width="100"	sortable="false" />
			<t:dgCol title="是否有巡检计划"	field="isHadInspection"				queryMode="single"	width="120"		dictionary="<%=StaticValue.DIC_TRUE_OR_FALSE_NUM %>" />
			<t:dgCol title="激光改造"		field="laserReconstruction"			queryMode="single"	query="true"	width="80"		dictionary="<%=StaticValue.DIC_TRUE_OR_FALSE_NUM %>" />
			<t:dgCol title="是否有本年度巡检计划"		field="hadThisYearIp"	hidden="true"	queryMode="single"	query="true"	width="80"		dictionary="<%=StaticValue.DIC_TRUE_OR_FALSE_NUM %>" defaultSelectVal="<%=StaticValue.DIC_TRUE_OR_FALSE_NUM_0 %>"/>
			
<%--			<t:dgCol title="创建人名称"		field="createName"			hidden="true"	queryMode="single"  width="120"></t:dgCol>--%>
<%--			<t:dgCol title="创建人登录名称"	field="createBy"			hidden="true"	queryMode="single"  width="120"></t:dgCol>--%>
<%--			<t:dgCol title="创建日期"		field="createDate"			hidden="true"	queryMode="single"	width="120"	formatter="yyyy-MM-dd"></t:dgCol>--%>
<%--			<t:dgCol title="更新人名称"		field="updateName"			hidden="true"	queryMode="single"	width="120"></t:dgCol>--%>
<%--			<t:dgCol title="更新人登录名称"	field="updateBy"			hidden="true"	queryMode="single"	width="120"></t:dgCol>--%>
			<t:dgCol title="更新日期"		field="updateDate"			hidden="true"	queryMode="single"	width="120"	formatter="yyyy-MM-dd"></t:dgCol>
			
			<t:dgCol title="操作" field="opt" width="100"></t:dgCol>
			<t:dgFunOpt title="生成巡检计划" funname="generatePlanInCol(id)" exp="serverState#eq#${esSeverState }"/>
			<t:dgToolBar title="批量新建巡检计划"	icon="icon-add"	url=""	funname="generatePlanInToolBar"></t:dgToolBar>
<%--			<t:dgToolBar title="新建巡检计划"		icon="icon-add"	url=""	funname="generatePlanInToolBar"></t:dgToolBar>--%>
		</t:datagrid>
	</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
	//给时间控件加上样式
	$("#zyGenerateInspectionPlanListtb").find("input[name='repairEndDate_begin']").attr({"class":"Wdate","id":"repairEndDate_begin"}).click(function(){
		WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'repairEndDate_end\')}'});
		});
	$("#zyGenerateInspectionPlanListtb").find("input[name='repairEndDate_end']").attr({"class":"Wdate","id":"repairEndDate_end"}).click(function(){
		WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'repairEndDate_begin\')}'});
		});
	$("#zyGenerateInspectionPlanListtb").find("input[name='lastYearInspectionDate_begin']").attr({"class":"Wdate","id":"lastYearInspectionDate_begin"}).click(function(){
		WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'lastYearInspectionDate_end\')}'});
		});
	$("#zyGenerateInspectionPlanListtb").find("input[name='lastYearInspectionDate_end']").attr({"class":"Wdate","id":"lastYearInspectionDate_end"}).click(function(){
		WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'lastYearInspectionDate_begin\')}'});
		});
	$("#zyGenerateInspectionPlanListtb").find("input[name='installDate_begin']").attr({"class":"Wdate","id":"installDate_begin"}).click(function(){
		WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'installDate_end\')}'});
		});
	$("#zyGenerateInspectionPlanListtb").find("input[name='installDate_end']").attr({"class":"Wdate","id":"installDate_end"}).click(function(){
		WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'installDate_begin\')}'});
		});
	territoryLink("zyGenerateInspectionPlanList","tsTerritory.territoryName");
	chooseBpForQueryParam("bpNo");
	//360 为 datagridTag.java中定义的宽度
<%--	var spanWidth = 2 * 360;--%>
<%--	if(window.screen.width > 1366){--%>
<%--		spanWidth = 3 * 360;--%>
<%--	}--%>
<%--	chooseBpForQueryParam("bpNo");--%>
<%--	var cloneNode1 = $("div[name='searchColums']>*:nth-child(1)").clone();--%>
<%--	var cloneNode2 = $("div[name='searchColums']>*:nth-child(1)").clone();--%>
<%--	$(cloneNode1).children().not(":first").remove();--%>
<%--	$(cloneNode1).children().first()--%>
<%--		.attr("title","是否在本年度默认巡检范围内").html("是否在本年度默认巡检范围内:").css({"text-overflow":"","-o-text-overflow":"","overflow":""})--%>
<%--		.after('<label><input type="radio" value="1" name="inThisYearInsScope" />是</label><label><input type="radio" value="0" name="inThisYearInsScope" />否</label>');--%>
<%--	$("div[name='searchColums']>*:nth-child(1)").before(cloneNode1);--%>
<%--	cloneNode2.html("默认巡检范围为：保修截止日期在本年，安装日期小于本年1月1日").css({"width":spanWidth + "px","color":"blue"}).insertAfter($("input[name='inThisYearInsScope']").parent().parent());--%>
	
	//$('<span style="color:blue;font-size:10px;">默认巡检范围为：保修截止日期大于等于本年1月1日，安装日期小于本年1月1日</span>').insertAfter($("select[name='inThisYearInsScope']").parent());
	$("div[name='searchColums']").prepend('<div style="padding:5px;"><span style="color:blue;font-size:10px;">默认巡检范围为：保修截止日期大于等于本年1月1日，安装日期小于本年1月1日</span></div>');
	setTimeout(function(){//延时调用查询，因为datagrid的field中的formatter 没有执行完毕
		zyGenerateInspectionPlanListsearch();//默认 不自动加载数据，调用查询按钮方法 查询，达到根据搜索条件加载数据的效果
	},500);
});

function generatePlanInToolBar(){
	var datas = $("#zyGenerateInspectionPlanList").datagrid("getSelections");
	if(datas.length == 0){
		tip("请选择要生成计划的设备!");
		return;
	}
	var equipmentIdsArr = new Array();
	$.each(datas,function(i,item){
		equipmentIdsArr.push(item.id);
	});
	generatePlan(equipmentIdsArr);
}
function generatePlanInCol(id){
	generatePlan(new Array([id]));
}
function generatePlan(equipmentIdsArr){
	var equipmentIds = equipmentIdsArr.join(",");
	$("#zyGenerateInspectionPlanListtb").parent().append('<div class="datagrid-mask" style="display:block"></div><div class="datagrid-mask-msg" style="display: block; left: 50%; margin-left: -58px;">验证中...</div>');
	$.ajax({
		url : "zyInspectionPlanController.do?checkEsServerState",
		data : {
			"equipmentIds" : equipmentIds
			},
		cache : false,
		dataType : 'json',
		type : 'POST',
		success : function(data){
			$("#zyGenerateInspectionPlanListtb").parent().find(".datagrid-mask").remove();
			$("#zyGenerateInspectionPlanListtb").parent().find(".datagrid-mask-msg").remove();
			if(data.success){
				if(equipmentIdsArr.length == 1){
					addOneTab("新建巡检计划","zyInspectionPlanController.do?goBatchGeneratePlan&esLength="+ equipmentIdsArr.length +"&equipmentIds="+equipmentIds,"");
				}else if(equipmentIdsArr.length > 1){
					createwindow("批量新建巡检计划","zyInspectionPlanController.do?goBatchGeneratePlan&esLength=" + equipmentIdsArr.length ,800,300);
					//createwindow("批量新建巡检计划","zyInspectionPlanController.do?goBatchGeneratePlan&equipmentIds="+equipmentIds,800,300);
				}
			}else{
				tip(data.msg);
			}
		}
	});
}
function hideMask(){//生成巡检计划回调 勿删
	lockmask(false);
	zyGenerateInspectionPlanListsearch();
}
</script>